<template>
  <div class="container">
    <div class="main_wrapper">
      <el-row>
        <el-col :xs="24" :sm="24" :md="12" :lg="12" class="card_col">
          <div v-if="caseList.length === 0">
            <el-empty :image-size="150" description="暂无案例"></el-empty>
          </div>
          <div class="left_wall" v-else>
            <div
              class="item_box"
              v-for="item in caseList"
              :key="item.id"
              @click="goCaseDetail(item.id)"
            >
              <el-image
                style="height: 100px; min-width: 135px"
                :src="imgUrl + item.img"
              ></el-image>
              <div class="item_desc">
                <div class="item_name">
                  {{ item.name }}
                </div>
                <div class="desc_box">
                  <dict-tag
                    :options="dict.type.plant_setting_type"
                    :value="item.plantSettingType"
                  />
                </div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="12" class="card_col">
          <div class="right_wall">
            <h3>导学</h3>
            <div class="word_box">
              {{ intro }}
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getCaseList } from '@/api/basecase.js'
import { getDicts } from '@/api/system/dict/data.js'

export default {
  name: 'Overview',
  dicts: ['plant_setting_type'],
  data() {
    return {
      query: {
        current: 1,
        size: 100,
        plantSettingType: ''
      },
      caseList: [],
      intro: ''
    }
  },
  created() {
    this.query.plantSettingType = this.$route.query.type
    this.getCaseList()
    this.getIntro()
  },
  mounted() {
  },
  computed: {
    imgUrl() {
      return process.env.VUE_APP_IP || ''
    },
  },
  methods: {
    async getIntro() {
      const res = await getDicts('plant_setting_type')
      const { data } = res
      const target = data.find(item => { return item.dictValue === this.query.plantSettingType })
      this.intro = target.introduce
    },
    async getCaseList() {
      const res = await getCaseList(this.query)
      const { data } = res
      this.caseList = data.records
    },
    goCaseDetail(id) {
      this.$router.push({ path: '/cdetail', query: { caseid: id } })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  margin: auto;
  padding-top: 20px;
  padding-bottom: 60px;
  width: 80%;
  min-height: calc(100vh - 200px);
}
.main_wrapper {
  width: 100%;
}
.card_col {
  padding: 0 10px;
  // min-height: 80vh;
  background: #fff;
}
.left_wall {
  padding: 5px 10px;
  width: 100%;
  // min-height: 80vh;
  .item_box {
    margin-bottom: 15px;
    height: 110px;
    border-radius: 3px;
    border: 1px solid #f1f2f3;
    overflow: hidden;
    display: flex;
    align-items: center;
    &:hover {
      cursor: pointer;
      box-shadow: 0 2px 14px 0 rgba(0, 0, 0, 0.1);
    }
    .item_desc {
      flex: 1;
      margin-left: 10px;
      overflow: hidden;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      .item_name {
        margin-bottom: 5px;
        font-size: 18px;
        line-height: 30px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .desc_box {
        flex: 1;
        font-size: 13px;
        overflow: hidden;
        ::v-deep span {
          padding: 5px;
          background: #e1f3d8;
        }
      }
    }
  }
}
.right_wall {
  padding: 5px 10px;
  width: 100%;
  .word_box {
    line-height: 25px;
    letter-spacing: 3px;
  }
}
</style>